import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'nonstandardOrderM', //非标指令
  state: {},
  effects: {
    //指令下达新增
    *orderSave({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardAsset.orderSave, payload);
      callback(response);
    },
    //簿记新增 修改
    *tradeBookSave({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardAsset.tradeBookSave, payload);
      callback(response);
    },
    //交易录入
    *tradeAdd({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardAsset.tradeAdd, payload);
      callback(response);
    },
    //查询基础信息
    *queryBaseInfo({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardAsset.queryBaseInfo, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        message.error(response ? response.msg : '查询非标基础信息失败!');
      }
    },
    //根据tradingCode获取基础信息
    *getBaseInfo({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardAsset.getBaseInfo, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        message.error(response ? response.msg : '获取非标基础信息失败!');
      }
    },

    // 获取非标利息
    *getInterest({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardAsset.getInterest, payload);
      if (response?.success) {
        callback(response?.data.interest);
      } else {
        message.error(response?.message || '获取非标利息失败!');
        callback(undefined);
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
